const config = require('../../../config/api.js');

Page({
  data: {
    ingTask: [],
    endTask: [],
    currentTab: 0
  },
  onLoad: function() {
    this.getMyTask();
    this.getIntegral()
  },

  getIntegral: function() {
    wx.request({
      url: config.integralUrl,
      method: 'GET',
      header: {
        'Authorization': 'Bearer ' + wx.getStorageSync('token')
      },
      success: (res) => {
        // console.log(res)
        this.setData({
          completePoint: res.data.finish_point
        })
      }
    })
  },
  getMyTask: function() {
    wx.request({
      url: config.receiveTask,
      method: 'GET',
      header: {
        'Authorization': 'Bearer ' + wx.getStorageSync('token')
      },
      success: (res) => {
        // console.log(res)
        this.setData({
          ingTask: res.data.ing,
          endTask: res.data.end
        })
      }
    })
  },

  swiperTab: function(e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current
    })
  },
  clickTab: function(e) {
    var that = this;
    if (that.data.currentTab == e.currentTarget.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.currentTarget.dataset.current
      })
    }
  },
  goDetail(e) {
    wx.navigateTo({
      url: '/pages/task/task-details/task-details?taskid=' + e.currentTarget.dataset.id,
    })
  }
})